package com.kantboot.file.service.impl;

import com.kantboot.file.entity.CesImage;
import com.kantboot.file.entity.CesVideo;
import com.kantboot.file.mapper.CesImageMapper;
import com.kantboot.file.mapper.CesVideoMapper;
import com.kantboot.file.service.CesVideoService;
import com.kantboot.util.FileIoUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Service
public class CesVideoServiceImpl implements CesVideoService {

    @Resource
    private CesVideoMapper videoMapper;

    @Override
    public CesVideo uploadVideo(MultipartFile video) {
        String path = FileIoUtil.imageTransferTo(video, "d:/aaa/aaa");
        CesVideo cesVideo = new CesVideo().setPath(path);
        videoMapper.insert(cesVideo);
        return cesVideo;
    }

    @Override
    public void showVideoById(Integer id, HttpServletResponse response) {
        CesVideo cesVideo=videoMapper.selectById(id);
        FileIoUtil.showVideoByPath(cesVideo.getPath(),response);
    }


}
